//
//  ZFBBottomListFlowLayout.m
//  01-ZFB
//
//  Created by My Mac on 2017/6/4.
//  Copyright © 2017年 MyMac. All rights reserved.
//

#import "ZFBHomeBottomListFlowLayout.h"

@implementation ZFBHomeBottomListFlowLayout
//准备布局
-(void)prepareLayout
{
    [super prepareLayout];
    //设置每行的item数量
    NSInteger itemCount = 4;
    //获取屏幕大小
    CGSize size = [UIScreen mainScreen].bounds.size;
    //设置间距
    CGFloat margin = 1;
    //设置item的宽
    CGFloat itemWidth = ( size.width - (itemCount -1) * margin ) / itemCount;
    //设置item的大小
    self.itemSize = CGSizeMake(itemWidth, itemWidth);
    //设置间距
    self.minimumLineSpacing = margin;
    self.minimumInteritemSpacing = margin;
    //设置边距
    self.sectionInset = UIEdgeInsetsMake(0, 0, 8, 0);
}

//返回数组中所有视图布局属性实例给定的矩形
-(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *attrs = [super layoutAttributesForElementsInRect:rect];
    for (UICollectionViewLayoutAttributes *attr in attrs) {
        if (attr.indexPath.section == 1) {
            //修改宽度，应该等于collectionView的宽度
            CGRect rect = attr.frame;
            rect.size.width = self.collectionView.bounds.size.width;
            attr.frame = rect;
            break;
        }
    }
    return attrs;
}
@end
